﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Common;

public partial class Stock_Stock_Add : System.Web.UI.Page
{
    protected int StockKey;

    protected string MenuType
    {
        get { return string.IsNullOrEmpty(Request["menutype"]) ? "" : Request["menutype"].ToString(); }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        StockKey = string.IsNullOrEmpty(Request["StockKey"]) ? 0 : Convert.ToInt32(Request["StockKey"]);

        if (!this.IsPostBack)
        {

            if (StockKey != 0)
            {
                Dat_Stock stock = new Dat_Stock();
                txt_StName.Text = stock.StName;
                txt_StSpec.Text = stock.StSpec;
                txt_Price.Text = stock.Price.ToString();
                //txt_Num.Text = stock.Num.ToString();

                btnSubmit.Text = "修 改";
            }
       }
    }

    //添加
    protected void btnSubmit_Click(object sender, EventArgs e)
    {

        if (StockKey == 0)
        {
            Dat_Stock stock = new Dat_Stock
            {
                StName = txt_StName.Text.Trim(),
                StSpec = txt_StSpec.Text.Trim(),
                Price =  Convert.ToDecimal(txt_Price.Text.Trim()),
                Num = 0,
                CreateTime = DateTime.Now,
                UserKey = Convert.ToInt32(Session["UserKey"])
            };

            if (new Stock().AddStock(stock))
            {
                WebUtility.JsAlertToGo("添加物品成功", "Stock_Add.aspx?menutype=311");
            }
        }
        else
        {
            Dat_Stock stock = new Dat_Stock
            {
                StockKey = StockKey,
                StName = txt_StName.Text.Trim(),
                StSpec = txt_StSpec.Text.Trim(),
                Price = Convert.ToDecimal(txt_Price.Text.Trim())
                //Num = Convert.ToInt32(txt_Num.Text.Trim()),
                //CreateTime = DateTime.Now,
                //UserKey = 6
            };

            if (new Stock().EditStock(stock))
            {
                WebUtility.JsAlertToGo("修改物品成功", "Stock_Add.aspx?menutype=311");
            }
        }
    }
}
